﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;

public partial class Manage_HospitalAdd : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAdmin);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        { }

    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {

        HZ.MBSM.Model.Hospital Hospital = new HZ.MBSM.Model.Hospital();
        HZ.MBSM.Model.Account Account = new HZ.MBSM.Model.Account();

        int i = 0;
        if (Hospital != null)
        {
            int rowCun = 0;
            Db db = new Db();
            System.Data.IDataReader dr;
            String strSql = "select count(accountid) as cun from dbo.v_account where accountname='" + SysFun.ToTrim(AccountName.Text) + "'  or dwname= '" + SysFun.ToTrim(HospitalName.Text) + "' or usercode='" + SysFun.ToTrim(txtUserCode.Text) + "'";
            dr = db.DataReader(strSql);
            if (dr.Read())
            {
                rowCun = SysFun.ToInt(dr["cun"]);
            }
            dr.Close();
            dr.Dispose();
            db.Close();
            if (rowCun > 0)
            {
                Response.Write("<script language=JavaScript>alert('该用户在数据库中已经存在！！！');</script>");
            }
            else
            {

                Account.AccountName = AccountName.Text;
                Account.Pwd_Bid = SysFun.PasswordEncrypt(Pwd_Bid.Text);
                Account.Type = Convert.ToUInt16(HZ.MBSM.DAL.AccountType.enumHospitale).ToString();
                Account.IsBid_Landing = "1";
                Hospital.UserCode = SysFun.ToTrim(txtUserCode.Text);
                Hospital.AreaId = SysFun.ToInt(Request.Form["AreaId"]);
                Hospital.HospitalName = HospitalName.Text;
                Hospital.IsOldLeader = Convert.ToBoolean(int.Parse(IsOldLeader.SelectedValue));
                Hospital.Lawer = txtLawer.Text;
                Hospital.PostCode = PostCode.Text;
                Hospital.RegistDate = System.DateTime.Now;
                Hospital.Telephone = Telephone.Text;
                Hospital.Sort = Sort.SelectedValue;
                Hospital.distinction = distinction.SelectedValue;
                Hospital.Email = txtEmail.Text;
                Hospital.bedNum = SysFun.ToInt(txtbedNum.Text);
                Hospital.memo1 = txtmemo1.Text;
                Hospital.LinkMan = txtLinkMan.Text;
                Hospital.Fax = txtFax.Text;
                Hospital.Address = Address.Text;
                i = HZ.MBSM.BLL.UserRegist.RegistHospital(Account, Hospital);
                Response.Write("<script>alert('保存成功！！！');</script>");
                HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
                HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "插入", "Hospital", Hospital.AccountId + "|" + Hospital.HospitalName + "|" + Hospital.UserCode + "|" + Hospital.AreaId, "../Magage/HospitalAdd.aspx");

                Response.Write("<script>window.opener.location.reload();window.close();</script>");
            }
        }


    }


}
